import React, { Component } from 'react'

import { PickerView } from 'antd-mobile'

import FilterFooter from '../../../../components/FilterFooter'

export default class FilterPicker extends Component {
  // constructor(props) {
  //   super(props)
  //   console.log('consturctor')
  // }
  state = {
    value: this.props.defaultVal
  }

  //此方案性能好,或者直接在FilterPicker组件标签上加上key属性,也能触发state初始化
  // componentDidUpdate(prevProps) {
  //   const { openType, defaultVal } = this.props
  //   if (openType !== prevProps.openType) {
  //     this.setState({
  //       value: defaultVal
  //     })
  //   }
  // }
  hidePicker = () => {
    this.props.hidePicker()
  }
  onSave = () => {
    // console.log(this.state.value)
    this.props.onSave(this.state.value)
  }

  onchange = value => {
    // console.log(value)
    this.setState({
      value
    })
  }

  render() {
    const { data, cols } = this.props
    return (
      <>
        {/* 选择器组件： */}
        <PickerView
          data={data}
          value={this.state.value}
          cols={cols}
          onChange={this.onchange}
        />

        {/* 底部按钮 */}
        <FilterFooter onCancel={this.hidePicker} onOk={this.onSave} />
      </>
    )
  }
}
